package hot_100;

public class 多数元素 {
    public static void main(String[] args) {

    }

    public int majorityElement(int[] nums) {
        int ans = nums[0];
        int sum = 0;
        for (int num : nums) {
            if (sum == 0)
                ans = num;
            if (num == ans)
                sum++;
            else {
                sum--;
            }
        }
        return ans;
    }

}
